package com.merry.mvc.exception;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

//ControllerAdvice：标识为一个组件。
@ControllerAdvice
public class ExceptionController {

    /**
     * ExceptionHandler: 设置匹配的异常类型
     * @param e
     * @param model
     * @return
     */
    @ExceptionHandler({ArithmeticException.class, NullPointerException.class})
    public String testException(Exception e, Model model){
        model.addAttribute("ex",e);
        System.out.println(e.getMessage());
        return "error";
    }
}
